package com.wxzz.elearing.course.api.app;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.course.dto.CurriculumCategoryDto;
import com.wxzz.elearing.course.entity.CurriculumCategory;
import com.wxzz.elearing.course.service.ICurriculumCategoryService;
import com.wxzz.elearning.common.exception.ServiceException;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程分类 前端控制器
 * </p>
 *
 * @author
 * @since 2021-03-10
 */
@RestController
@RequestMapping("/wx-curriculum-category")
@Api(tags = "课程分类接口")
public class WxCurriculumCategoryController {

    @Autowired
    private ICurriculumCategoryService curriculumCategoryService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;


    @ApiOperation(value = "列出课程分类搜索(小程序)", notes = "列出课程分类搜索(小程序)", httpMethod = "POST",tags = "小程序")
    @RequestMapping(value = "listCurriculumCategory/{type}", method = RequestMethod.POST)
    public ReturnVO<List<CurriculumCategory>> listCurriculumCategory(@RequestHeader String token, @ApiParam("0-平台 1-企业") @PathVariable Integer type) {
        if (type == 0) {
            return curriculumCategoryService.listCurriculumCategory(0L);
        }
        if (type == 1) {
            JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
            return curriculumCategoryService.listCurriculumCategory(jsonObject.getLong("enterpriseId"));
        }
        throw new ServiceException("请输入type 0-平台 1-企业");
    }


}
